package br.ufba.graph.clustering;

import cern.colt.matrix.impl.SparseDoubleMatrix2D;

public class ClusteringApp {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/**
		 * Calculating the 1st iteration
		 */
		
		//Building the Laplacian Matrix
		SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(10,10);

		matrix.set(0, 0, 2); matrix.set(0, 1, 0); matrix.set(0, 2, -2); matrix.set(0, 3, 0); matrix.set(0, 4, 0); matrix.set(0, 5, 0); matrix.set(0, 6, 0); matrix.set(0, 7, 0); matrix.set(0, 8, 0); matrix.set(0, 9, 0);
		matrix.set(1, 0, 0); matrix.set(1, 1, 5); matrix.set(1, 2, -5); matrix.set(1, 3, 0); matrix.set(1, 4, 0); matrix.set(1, 5, 0); matrix.set(1, 6, 0); matrix.set(1, 7, 0); matrix.set(1, 8, 0); matrix.set(1, 9, 0);
		matrix.set(2, 0, -2); matrix.set(2, 1, -5); matrix.set(2, 2, 14); matrix.set(2, 3, -5); matrix.set(2, 4, 0); matrix.set(2, 5, 0); matrix.set(2, 6, -2); matrix.set(2, 7, 0); matrix.set(2, 8, 0); matrix.set(2, 9, 0);
		matrix.set(3, 0, 0); matrix.set(3, 1, 0); matrix.set(3, 2, -5); matrix.set(3, 3, 5); matrix.set(3, 4, 0); matrix.set(3, 5, 0); matrix.set(3, 6, 0); matrix.set(3, 7, 0); matrix.set(3, 8, 0); matrix.set(3, 9, 0);
		matrix.set(4, 0, 0); matrix.set(4, 1, 0); matrix.set(4, 2, 0); matrix.set(4, 3, 0); matrix.set(4, 4, 4); matrix.set(4, 5, -2); matrix.set(4, 6, -2); matrix.set(4, 7, 0); matrix.set(4, 8, 0); matrix.set(4, 9, 0);
		matrix.set(5, 0, 0); matrix.set(5, 1, 0); matrix.set(5, 2, 0); matrix.set(5, 3, 0); matrix.set(5, 4, -2); matrix.set(5, 5, 4); matrix.set(5, 6, -2); matrix.set(5, 7, 0); matrix.set(5, 8, 0); matrix.set(5, 9, 0);
		matrix.set(6, 0, 0); matrix.set(6, 1, 0); matrix.set(6, 2, -2); matrix.set(6, 3, 0); matrix.set(6, 4, -2); matrix.set(6, 5, -2); matrix.set(6, 6, 9); matrix.set(6, 7, -3); matrix.set(6, 8, 0); matrix.set(6, 9, 0);
		matrix.set(7, 0, 0); matrix.set(7, 1, 0); matrix.set(7, 2, 0); matrix.set(7, 3, 0); matrix.set(7, 4, 0); matrix.set(7, 5, 0); matrix.set(7, 6, -3); matrix.set(7, 7, 10); matrix.set(7, 8, -3); matrix.set(7, 9, -4);
		matrix.set(8, 0, 0); matrix.set(8, 1, 0); matrix.set(8, 2, 0); matrix.set(8, 3, 0); matrix.set(8, 4, 0); matrix.set(8, 5, 0); matrix.set(8, 6, 0); matrix.set(8, 7, -3); matrix.set(8, 8, 3); matrix.set(8, 9, 0);
		matrix.set(9, 0, 0); matrix.set(9, 1, 0); matrix.set(9, 2, 0); matrix.set(9, 3, 0); matrix.set(9, 4, 0); matrix.set(9, 5, 0); matrix.set(9, 6, 0); matrix.set(9, 7, -4); matrix.set(9, 8, 0); matrix.set(9, 9, 4);

		//Running the Lanczos decomposition
		LanczosDecomposition decomp = new LanczosDecomposition(matrix);

		//Printing results
		for(int i=0; i < decomp.getEigenvectors().columns(); i++)
			System.out.println("Value " + (i+1) + ": " + decomp.getEigenvectors().get(i, 1));
		System.out.println("Eigenvalue: " + decomp.getEigenvalues().get(1));


		/**----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------**/

		/**
		 * Calculating the 2nd iteration
		 */
		
		//Building the Laplacian Matrix
		SparseDoubleMatrix2D matrix2 = new SparseDoubleMatrix2D(6,6);

		matrix2.set(0, 0, 4); matrix2.set(0, 1, -2); matrix2.set(0, 2, -2); matrix2.set(0, 3, 0); matrix2.set(0, 4, 0); matrix2.set(0, 5, 0);
		matrix2.set(1, 0, -2); matrix2.set(1, 1, 4); matrix2.set(1, 2, -2); matrix2.set(1, 3, 0); matrix2.set(1, 4, 0); matrix2.set(1, 5, 0);
		matrix2.set(2, 0, -2); matrix2.set(2, 1, -2); matrix2.set(2, 2, 7); matrix2.set(2, 3, -3); matrix2.set(2, 4, 0); matrix2.set(2, 5, 0);
		matrix2.set(3, 0, 0); matrix2.set(3, 1, 0); matrix2.set(3, 2, -3); matrix2.set(3, 3, 10); matrix2.set(3, 4,-3); matrix2.set(3, 5, -4);
		matrix2.set(4, 0, 0); matrix2.set(4, 1, 0); matrix2.set(4, 2, 0); matrix2.set(4, 3, -3); matrix2.set(4, 4, 3); matrix2.set(4, 5, 0);
		matrix2.set(5, 0, 0); matrix2.set(5, 1, 0); matrix2.set(5, 2, 0); matrix2.set(5, 3, -4); matrix2.set(5, 4, 0); matrix2.set(5, 5, 4);

		//Running the Lanczos decomposition
		LanczosDecomposition decomp2 = new LanczosDecomposition(matrix2);

		//Printing results
		for(int i=0; i < decomp2.getEigenvectors().columns(); i++)
			System.out.println("Value " + (i+1) + ": " + decomp2.getEigenvectors().get(i, 1));
		System.out.println("Eigenvalue: " + decomp2.getEigenvalues().get(1));



	}

}
